package tx.bjdacp.action;

import java.util.Map;

import tx.bjdacp.model.UserInfo;
import tx.bjdacp.service.UserInfoManager;
import tx.bjdacp.util.SpringSecurityUtils;
import tx.bjdacp.util.WebUtils;



import javacommon.base.BaseStruts2Action;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.web.scope.Flash;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class PortalAction extends BaseStruts2Action implements Preparable,ModelDriven{

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return null;
	}
	private UserInfoManager userInfoManager;
	public void setUserInfoManager(UserInfoManager manager) {
		this.userInfoManager = manager;
	}

	/**
	 * 进入主页
	 * @return
	 */
	public String index(){
		String username=SpringSecurityUtils.getCurrentUserName();
		if(!SpringSecurityUtils.isAnonymousUser()){

				tx.bjdacp.model.UserInfo u=userInfoManager.getByUsername(username);
				WebUtils.setUserInSession(u);

		}
		return "/index.jsp";
	}

	private String password;

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * 修改密码
	 * @return
	 */
	public String changePassword(){
		if(!SpringSecurityUtils.isAnonymousUser()){
			UserInfo u=userInfoManager.getById(WebUtils.getUserInSession().getUserInfoId());
			u.setPassword(password);
			userInfoManager.saveOrUpdate(u);
			Flash.current().success(UPDATE_SUCCESS);
		}
		return "!/pages/Portal/main.do";
	}


	/**
	 * 进入main页面
	 * @return
	 */
	public String main(){


		return "!/pages/DrugSellUnit/list.do";
	}






}
